package com.iwomy.envpro.platform.mapper;

import com.iwomy.envpro.common.data.datascope.EnvproBaseMapper;
import com.iwomy.envpro.platform.entity.AirSiteEntity;
import com.iwomy.envpro.platform.entity.CodeAreaEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CodeAreaMapper extends EnvproBaseMapper<CodeAreaEntity> {
	@Select("SELECT DATA.*  " +
			"FROM ( SELECT @ids AS _ids, ( SELECT @ids := GROUP_CONCAT( id ) " +
			"FROM code_area WHERE FIND_IN_SET( pid, @ids ) ) AS cids, @l := @l + 1 AS LEVEL  " +
			"FROM code_area, ( SELECT @ids := #{id}, @l := 0 ) b  WHERE @ids IS NOT NULL  ) ID, code_area DATA  WHERE FIND_IN_SET( DATA.id, ID._ids ) ORDER BY id")
	List<CodeAreaEntity> recursionAll(@Param("id")Long id);
}